Re: calling a batch file using dxl pommCannelle - Wed Jun 17 10:32:32 EDT 2015
In fact you can wait the end of an external treatment ...
2 methods are availables...
The official one (not well documented i guess ?)
int win32SystemWait_(string cmd, string res, int time_out)
And the handmade one (you can find them on the smartDXL forum ... )
string command_system (string cmd, int wait_time_in_sec) {
int wait_time_in_ms = 1000*wait_time_in_sec
string errmsg = null
// create the lock file : while it exists the command is still running
string lockfile = tempFileName // ( os give us a legal temp file )
string errmsgfile = tempFileName
Stream out = write lockfile // create the temp file ...
close out
// make the batchfile command
string batchfile = tempFileName ".bat"
out = write batchfile
out << cmd " 2> \"" errmsgfile "\"\n" // ( error treatment )
out << "if %errorlevel% EQU 0 del \"" errmsgfile "\"\n"
out << "del \"" lockfile "\"\n"
close out
// run the batchfile command
system batchfile // send the batchfile command to system
// Wait for the batchfile command to end
int delay_in_ms = 0
while (fileExists_ lockfile) { // wait the lock file deletion
if (delay_in_ms > wait_time_in_ms){ // ( timer )
// abort if delay > tempo s
errmsg = "Timeout ! (" wait_time_in_sec " sec)"
break
}
delay_in_ms += 100
sleep_(100) // sleep_ funcion used for 100 ms
}
deleteFile batchfile // ( clean the batch file )
// return error message if any
if (null errmsg && fileExists_ errmsgfile){
errmsg = readFile errmsgfile
}
deleteFile errmsgfile
return errmsg
}
// Add a default timer value -> 30 sec
string command_system (string cmd ) {
return command_system( cmd"", 30)
}
Be aware that you're waiting the end of the treatment and can't do anything during this time ;)
And to use a known file as buffer to get returned values seems to be the simpliest way ...
Have fun !
|